package a66weding.com.jiehuntong.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.base.BaseActivity;

/**
 * Created by admin on 2016/7/5.
 */
public abstract class MyBaseFragment  extends Fragment implements  KeyEvent.Callback{
    protected static int mDefaultColor;
    /**
     * 根元素
     */
    protected View mRootView;
    /**
     * 布局渲染工具
     */
    protected LayoutInflater mInflater;
    protected BaseActivity mHostActivity;
    protected Context mContext;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mInflater = inflater;
        mContext = inflater.getContext();
        return null;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mHostActivity = (BaseActivity) getActivity();
        mRootView=initRootView();
    }

    /**
     * 初始化View,加载布局
     *
     * @return 布局
     */
    public abstract View initRootView();

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        return false;
    }

    @Override
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {

        return false;
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {

        return false;
    }

    @Override
    public boolean onKeyMultiple(int keyCode, int count, KeyEvent event) {

        return false;
    }
    /**
     * 填充某View下的某TextView
     * @param rootView TextView的父view
     * @param resId TextView 的id
     * @param content TextView 文本内容
     */
    protected void fillTextView(View rootView,int resId,String content){
        TextView tv = (TextView) rootView.findViewById(resId);
        tv.setText(content);

    }

    protected void setTitleTv(int id) {
        TextView tv = (TextView) mRootView.findViewById(R.id.title_tv);
        tv.setText(id);
    }

    protected void setTitleTv(String str) {
        TextView tv = (TextView)  mRootView.findViewById(R.id.title_tv);
        tv.setText(str);
    }


    protected void setNextTv(String str) {
        TextView tv = (TextView)  mRootView.findViewById(R.id.next_tv);
        tv.setVisibility(View.VISIBLE);
        tv.setText(str);

    }

    protected TextView getNextTv() {

        return (TextView)  mRootView.findViewById(R.id.next_tv);
    }

    protected void setBackGone() {
        View tv =  mRootView.findViewById(R.id.ly_back);
        tv.setVisibility(View.GONE);
    }

    public void back(View view) {
        getActivity().finish();
    }

    @SuppressLint("NewApi")
    protected void setNextTvBG(Drawable drawable) {
        TextView tv = (TextView)  mRootView.findViewById(R.id.next_tv);
        tv.setBackground(drawable);
    }
    protected void setNextImage(int id) {
        TextView tv = (TextView)  mRootView.findViewById(R.id.next_tv);
        tv.setVisibility(View.GONE);

    }
    protected void setNextOnClick(View.OnClickListener onClick) {
        TextView tv = (TextView)  mRootView.findViewById(R.id.next_tv);
        tv.setOnClickListener(onClick);
    }

    protected void setNextGone() {
        TextView tv = (TextView)  mRootView.findViewById(R.id.next_tv);
        tv.setVisibility(View.GONE);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

}
